<template>
  <div class="aspp-container">
    <div class="head">
      <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch">
        <el-form-item label="" prop="">
          <el-input v-model="queryParams.query" placeholder="会员姓名/手机号" clearable style="width: 300px" />
        </el-form-item>
        <el-form-item label="订单状态：" prop="">
          <el-select v-model="queryParams.status" placeholder="请选择" filterable clearable style="width: 280px">
            <el-option v-for="(item,index) in couponStatusLs" :key="index" :label="item.value" :value="item.id" />
          </el-select>
        </el-form-item>
        <!-- <el-form-item label="核销店铺：" prop="">
          <el-select v-model="queryParams.shopIdList" multiple placeholder="请选择" filterable clearable
            style="width: 280px">
            <el-option v-for="item in shopList" :key="item.id" :label="item.value" :value="item.id" />
          </el-select>
        </el-form-item> -->
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-form>
    </div>
    <div class="num_detail">
      <div class="num_detail_box">活动数据：</div>
      <div class="num_detail_box">订单金额：￥{{info.orderMoney}}</div>
      <div class="num_detail_box">订单笔数：{{info.orderCount}}</div>
      <div class="num_detail_box">奖池金额：￥{{info.jackpotMoney}}</div>
      <div class="num_detail_box">退款笔数：{{info.refundOrderCount}}</div>
      <div class="num_detail_box">退款金额：￥{{info.refundMoney}}</div>
    </div>
    <div class="listBox">
      <div class="listBox_head">
        <div class="listBox_head_l">
          <el-button type="primary" @click="dataConfiguration">奖池数据配置</el-button>
          <div class="listBox_head_l_box">虚拟奖池金额：￥{{configureInfo.virtualMoney}}</div>
          <div class="listBox_head_l_box">综合排名计算配置 购买排名系数：{{configureInfo.buyRankCoefficient}}</div>
          <div class="listBox_head_l_box">
            <span>核销排名系数：{{configureInfo.verificationRankCoefficient}}</span>
            <el-popover placement="top-start" title="综合排行计算规则：" trigger="hover" content="">
              <div>1、购买排名得分*购买排名系数+核销排名得分*核销排名系数按每笔订单计算总分越高排名越高</div>
              <div>2、排名得分按订单数量取值 订单数量50单第一名为50分,第二名为49分</div>
              <div>3、若计算出综合排名得分相同时，按核销时间进行排序 核销越早排名越靠前。</div>
              <div slot="reference" class="el-icon-warning tips_icon"></div>
            </el-popover>
          </div>
        </div>
        <export-excel-button title="交易明细" action="/shenye/punch/jackpot/export" :type="'2'" :params="ExportParams" />
      </div>
      <el-table v-loading="loading" :data="tabList" stripe border>
        <el-table-column label="序号" align="center" type="index" width="64px" />
        <el-table-column label="订单状态" align="center" prop="status" :show-overflow-tooltip="true" width="120px">
          <template slot-scope="scope">
            <dict-tag :options="couponStatusLs" :value="scope.row.status" />
          </template>
        </el-table-column>
        <el-table-column label="订单编号" align="center" prop="orderId" width="120" />
        <!-- <el-table-column label="券码" align="center" prop="couponNo"></el-table-column> -->
        <!-- <el-table-column label="券有效期" align="center" prop="validityTime" /> -->
        <el-table-column label="会员姓名" align="center" prop="name" />
        <el-table-column label="手机号" align="center" prop="phone" />
        <el-table-column label="支付金额" align="center" prop="payMoney" />
        <el-table-column label="购买时间" align="center" prop="buyTime" width="155" />
        <el-table-column label="核销时间" align="center" prop="verificationTime" width="155" />
        <!-- <el-table-column label="核销店铺" align="center" prop="verificationShopName" /> -->
        <!-- <el-table-column label="退款金额" align="center" prop="refundMoney" /> -->
        <!-- <el-table-column label="平台佣金" align="center" prop="refundCommission" /> -->
        <el-table-column label="购买排名" align="center" prop="buyRank" width="120" sortable />
        <el-table-column label="核销排名" align="center" prop="verificationRank" width="120" sortable />
        <el-table-column label="综合排行" align="center" prop="comprehensiveRank" width="120" sortable />
      </el-table>

      <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
        @pagination="getList" />
    </div>
    <!-- 奖池数据配置 -->
    <el-dialog title="奖池数据配置" :visible.sync="dialogVisible" width="600px" :close-on-click-modal="false" @close="cancel">
      <el-form :model="ruleForm" :rules="rules" ref="ruleForm" :label-width="labelWidth" class="demo-ruleForm"
        v-loading='dialogLoading'>
        <el-form-item label="虚拟奖池金额：" prop="virtualMoney">
          <el-input v-model.number="ruleForm.virtualMoney" placeholder="请输入" :style="{width: inputWidth}">
            <template slot="append">元</template>
          </el-input>
        </el-form-item>
        <el-form-item label="购买排名系数：" prop="buyRankCoefficient">
          <el-input v-model="ruleForm.buyRankCoefficient" placeholder="请输入" :style="{width: inputWidth}"></el-input>
        </el-form-item>
        <el-form-item label="核销排名系数：" prop="verificationRankCoefficient">
          <el-input v-model="ruleForm.verificationRankCoefficient" placeholder="请输入" :style="{width: inputWidth}"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm('ruleForm')" :loading="AgreeLoading">确认提交</el-button>
        <el-button @click="dialogVisible=false">取 消</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
  import {
    jackpotList,
    jackpotShopList,
    jackpotStatistics,
    jackpotDetail,
    updatePushJackpot
  } from "@/api/consumeMiningManagement/onlineClockingActivity";
  import ExportExcelButton from "@/components/ExportExcelButton/index";
  export default {
    // dicts: ['equity_card_issue_type', 'equity_card_sell_status'],
    name: "",
    components: {
      ExportExcelButton
    },
    data() {
      return {
        // 遮罩层
        loading: false,
        // 导出遮罩层
        exportLoading: false,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        shopIdList: [],
        // 总条数
        total: 0,
        // 表格数据
        tabList: [],
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          punchActivityId: '', //打卡活动id
          query: '', //券码/会员姓名/手机号
          shopIdList: [], //店铺id数组
          status: '', //券状态 shenye_customer_coupon_status 1 待使用 2 已核销 3 已退款 4 已过期
        },
        shopList: [], //店铺下拉
        couponStatusLs: [], //券状态下拉
        info: {},
        configureInfo:{},//配置数据
        dialogVisible: false,
        labelWidth: '120px',
        inputWidth: '300px',
        dialogLoading: false,
        AgreeLoading: false,
        ruleForm: {
          buyRankCoefficient: '', //购买排名系数
          id: '', //主键id
          verificationRankCoefficient: '', //核销排名系数
          virtualMoney: '', //虚拟奖池金额
        },
        rules: {
          virtualMoney: [{
            required: true,
            message: '请输入虚拟奖池金额',
            trigger: ['change', 'bulr'],
          }],
          buyRankCoefficient: [{
            required: true,
            message: "请输入购买排名系数",
            trigger: ['change', 'bulr'],
          }],
          verificationRankCoefficient: [{
            required: true,
            message: "请输入核销排名系数",
            trigger: ['change', 'bulr'],
          }],
        },
      };
    },
    computed: {
      ExportParams() {
        const params = {
          ...this.queryParams,
        };
        return params;
      },
    },
    created() {
      let id = this.$route.query.id
      if (id != undefined) {
        this.queryParams.punchActivityId = id
      }
      this.getCouponStatusLs();
      this.getShopList();
      this.getJackpotStatistics();
      this.getJackpotDetail();
      this.getList();
    },
    methods: {
      //获取状态字典
      getCouponStatusLs() {
        var dictType = "shenye_punch_activity_order_coupon_status";
        this.$getSelectList(dictType)
          .then((res) => {
            var arr = [{
              id: "",
              value: "全部",
            }, ];
            this.couponStatusLs = arr.concat(res.result[0].dictList);
          })
          .finally(() => {
            this.loading = false;
          });
      },
      //查询核销店铺下拉框
      getShopList() {
        jackpotShopList().then(response => {
          this.shopList = response.result
        });
      },
      // 查询活动数据
      getJackpotStatistics() {
        jackpotStatistics(this.queryParams).then(response => {
          this.info = response.result
        });
      },
      /** 查询列表 */
      getList() {
        this.loading = true;
        jackpotList(this.queryParams).then(response => {
          this.tabList = response.result.records;
          this.total = response.result.total;
          this.loading = false;
        });
      },
      // 表单重置
      resetQuery() {
        this.queryParams.pageNum = 1
        this.queryParams.query = ''
        this.queryParams.shopIdList = []
        this.queryParams.status = ''
        // this.resetForm("form");
        this.getList();
        this.getJackpotStatistics()
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
        this.getJackpotStatistics()
      },
      getJackpotDetail(){ //奖池数据配置获取
        jackpotDetail(this.queryParams.punchActivityId).then(response => {
          this.ruleForm = response.result
          this.configureInfo = { ...response.result }
        }).catch(() => {
          
        });
      },
      dataConfiguration() { //奖池数据配置
        this.dialogVisible = true
      },
      cancel(){ //取消
        this.getJackpotDetail()
        this.dialogVisible = false
      },
      submitForm(formName) {
        //创建确定
        this.$refs[formName].validate((valid) => {
          if (valid) {
            this.AgreeLoading = true
            var params = {
              ...this.ruleForm,
            };
            updatePushJackpot(params).then((res) => {
                this.$message({
                  message: "提交成功",
                  type: "success",
                });
                setTimeout(() => {
                  this.dialogVisible = false
                  this.AgreeLoading = false
                  this.getJackpotDetail()
                  this.getList()
                }, 1000);
              })
              .catch(() => {
                this.AgreeLoading = false;
              });

          } else {
            console.log("error submit!!");
            return false;
          }
        });
      },
    }
  };

</script>
<style scoped>
  .head {
    box-shadow: 0px 4px 12px 0px rgb(1 41 99 / 6%);
    background-color: #fff;
    border-radius: 8px;
    padding: 20px 20px 0;
  }

  .listBox {
    box-shadow: 0px 4px 12px 0px rgb(1 41 99 / 6%);
    background-color: #fff;
    border-radius: 8px;
    padding: 20px 20px;
    margin-top: 10px;
  }

  .listBox_head {
    width: 100%;
    padding-bottom: 20px;
    display: flex;
    align-content: center;
    justify-content: space-between;
  }

  .listBox_head_l {
    display: flex;
    align-items: center;
  }

  .listBox_head_l_box {
    font-size: 15px;
    margin-left: 20px;
    color: #333;
  }

  .tips_icon {
    cursor: pointer;
    font-size: 16px;
    margin-left: 10px;
    color: #ff7418;
  }

  .num_detail {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    box-shadow: 0px 4px 12px 0px rgb(1 41 99 / 6%);
    background-color: #fff;
    border-radius: 8px;
    padding: 20px;
    margin-top: 10px;
  }

  .num_detail_box {
    color: #333;
    font-size: 16px;
    margin-right: 30px;
  }

</style>
